package com.jiaze.crud;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

import com.jiaze.entity.User;
import com.jiaze.util.DBUtils;

public class TestRUUD {
  @Test
 public void testselect(){
	  Connection conn = null;
	  Statement stmt = null;
	  ResultSet rs =null;
	  try {
		conn = DBUtils.getConnection();
		stmt = conn.createStatement();
		rs = stmt.executeQuery("select * from users");
		List<User>list =new ArrayList<User>();
		while(rs.next()){
			User u = new User();
			u.setId(rs.getInt(1));
			u.setName(rs.getString(2));
			u.setPassword(rs.getString(3));
			u.setEmail(rs.getString(4));
			u.setBirthday(rs.getTime(5));
			list.add(u);
		}
		for (User user : list) {
			System.out.println(user);
		}
		
		
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	  finally{
		  DBUtils.closeAll(rs, stmt, conn);
		  
	  }
	  
	  
	  
	  
	  
	  
	  
  }
}
